package com.FengChaoSystem.service.UserService;

import com.FengChaoSystem.dao.UserDao;
import com.FengChaoSystem.pojo.Order;
import com.FengChaoSystem.pojo.User;
import com.FengChaoSystem.service.UserImpl;
import com.FengChaoSystem.untils.SqlSessionFactoryUtils;
import com.Mybatis.session.SqlSession;
import com.Mybatis.session.SqlSessionFactory;

public class UserService implements UserImpl {
    SqlSessionFactory sqlSessionFactory= SqlSessionFactoryUtils.getSqlSessionFactory();

    @Override
    public User getImg(User user) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        User result = mapper.getImg(user);
        sqlSession.close();
        return result;
    }

    @Override
    public void addImg(User user) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        mapper.addImg(user);
        sqlSession.commit();
        sqlSession.close();

    }

    @Override
    public void resetPassWord(User user) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        mapper.resetPassWord(user);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public User selectUserInfo(User target) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        User result = mapper.selectUserInfo(target);
        sqlSession.close();
        return result;
    }

    @Override
    public void addOrder(Order order) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        mapper.addOrder(order);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public Order hasOnlyId(Order order) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        Order result = mapper.hasOnlyId(order);
        sqlSession.close();
        return result;
    }

    @Override
    public User selectNowMoney(User target) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        User result = mapper.selectNowMoney(target);
        sqlSession.close();
        return result;
    }

    @Override
    public void updateNowMoney(User user) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        mapper.updateNowMoney(user);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void updateInfoOfUser(User user) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        mapper.updateInfoOfUser(user);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void updateReceivePhone(Order order) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        mapper.updateReceivePhone(order);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public User selectUserInfoByReceivePhone(User target) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        User result = mapper.selectUserInfoByReceivePhone(target);
        sqlSession.close();
        return result;
    }


}
